#region Summary

// 
// Owner : JackieHan 
// 
// Solution : DailyCollection 
// 
// Project : Jackie.Utility.Notify
// 
// File : TitleCollection.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 可订阅的消息标题集合
// 
// History : 
//			2011-04-26 11:21:54	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;

#endregion

namespace Jackie.Utility.Notify.Domain
{
    /// <summary> 
    /// 可订阅的消息标题集合
    /// </summary>
    public class TitleCollection
    {
        private static TitleCollection instance;
        private static readonly object LockObject = new object();

        public static TitleCollection GetInstance()
        {
            if (instance == null)
            {
                lock (LockObject)
                {
                    if (instance == null)
                        instance = new TitleCollection();
                }
            }
            return instance;
        }

        private TitleCollection()
        {
            titles = new Dictionary<string, TitleInfo>();
        }

        private IDictionary<string, TitleInfo> titles;

        public void Add(TitleInfo info)
        {
            if (!titles.ContainsKey(info.Code))
            {
                titles.Add(info.Code, info);
            }
        }

        public bool Contains(TitleInfo info)
        {
            return titles.ContainsKey(info.Code);
        }

        public bool Contains(string titleCode)
        {
            return titles.ContainsKey(titleCode);
        }

        public bool Remove(string titleCode)
        {
            return titles.Remove(titleCode);
        }

        public IDictionary<string, TitleInfo> GetAllTitles()
        {
            return titles;
        }

        public TitleInfo GetTitle(string titleCode)
        {
            return titles[titleCode];
        }
    }
}